package cn.iocoder.yudao.module.agent.convert.user;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.agent.base.MemberRespVO;
import cn.iocoder.yudao.module.agent.controller.admin.withdrawaccount.vo.AgentWithdrawAccountRespVO;
import cn.iocoder.yudao.module.agent.convert.base.AgentConvert;
import cn.iocoder.yudao.module.agent.convert.withdrawaccount.AgentWithdrawAccountConvert;
import cn.iocoder.yudao.module.agent.dal.dataobject.withdrawaccount.AgentWithdrawAccountDO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import com.fasterxml.classmate.MemberResolver;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.agent.controller.admin.user.vo.*;
import cn.iocoder.yudao.module.agent.dal.dataobject.user.AgentUserDO;

/**
 * 代理人 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface AgentUserConvert {

    AgentUserConvert INSTANCE = Mappers.getMapper(AgentUserConvert.class);

    AgentUserDO convert(AgentUserCreateReqVO bean);

    AgentUserDO convert(AgentUserUpdateReqVO bean);

    AgentUserRespVO convert(AgentUserDO bean);

    List<AgentUserRespVO> convertList(List<AgentUserDO> list);

    PageResult<AgentUserRespVO> convertPage(PageResult<AgentUserDO> page);

    List<AgentUserExcelVO> convertList02(List<AgentUserDO> list);

    default AgentUserRespVO convert02(AgentUserDO bean, MemberRespVO memberRespVO, AgentWithdrawAccountRespVO accountRespVO){
        if ( bean == null ) {
            return null;
        }

        AgentUserRespVO agentUserRespVO = new AgentUserRespVO();

        agentUserRespVO.setUserId( bean.getUserId() );
        agentUserRespVO.setBrokerageRate( bean.getBrokerageRate() );
        agentUserRespVO.setEnabled( bean.getEnabled() );
        agentUserRespVO.setBrokerage( bean.getBrokerage() );
        agentUserRespVO.setFrozenBrokerage( bean.getFrozenBrokerage() );
        agentUserRespVO.setWithdrawBrokerage( bean.getWithdrawBrokerage() );
        agentUserRespVO.setWithdrawId( bean.getWithdrawId() );
        agentUserRespVO.setId( bean.getId() );
        agentUserRespVO.setCreateTime( bean.getCreateTime() );

        agentUserRespVO.setMember(memberRespVO);
        agentUserRespVO.setWithdrawAccount(accountRespVO);

        return agentUserRespVO;
    }

    default List<AgentUserRespVO> convertList02(List<AgentUserDO> agentUserDOList, Map<Long, MemberUserRespDTO> memberMap, Map<Long, AgentWithdrawAccountDO> accountMap) {
        List<AgentUserRespVO> list = new ArrayList<>();
        agentUserDOList.forEach(agentUserDO -> {
            AgentWithdrawAccountRespVO accountRespVO = AgentWithdrawAccountConvert.INSTANCE.convert(accountMap.get(agentUserDO.getUserId()));
            MemberRespVO memberRespVO = AgentConvert.INSTANCE.covnertMember(memberMap.get(agentUserDO.getUserId()));
            list.add(convert02(agentUserDO, memberRespVO, accountRespVO));
        });

        return list;
    }

    default PageResult<AgentUserRespVO> convertPage02(PageResult<AgentUserDO> page, Map<Long, MemberUserRespDTO> memberMap, Map<Long, AgentWithdrawAccountDO> accountMap){
        if ( page == null ) {
            return null;
        }

        PageResult<AgentUserRespVO> pageResult = new PageResult<AgentUserRespVO>();
        List<AgentUserRespVO> list = convertList02(page.getList(), memberMap, accountMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }

}
